#!/usr/bin/python
# -*- coding: utf-8-*-
import urllib
import sgmllib
import time
import logging
import datetime
from google.appengine.ext import db


def update_database():
    old_record_query = Hrecord.all().order('-date')


    while True:
        items = old_record_query.fetch(1000)
        for one_item in items:
            record = Datalog(
                qfts=one_item.qfts,
                qfmj=one_item.qfmj,
                xfts=one_item.xfts,
                xfmj=one_item.xfmj,
                clfts=one_item.clfts,
                clfmj=one_item.clfmj,
                disp_date=one_item.disp_date
            )
            y,m,d = one_item.disp_date.split('-')
            record.date = datetime.datetime(int(y), int(m), int(d))
            record.put()
            logging.info('w '+record.disp_date)
        break
    '''
    record_query = Datalog.all().order('-date')
    records = record_query.fetch(10000)
    for i in records:
      i.delete()
    '''
    return

class Hrecord(db.Model):
    date = db.DateProperty(auto_now_add=True)
    qfts = db.IntegerProperty()
    qfmj = db.IntegerProperty()
    xfts = db.IntegerProperty()
    xfmj = db.IntegerProperty()
    clfts = db.IntegerProperty()
    clfmj = db.IntegerProperty()
    disp_date = db.StringProperty()

class Datalog(db.Model):
    date = db.DateTimeProperty(auto_now_add=True)
    qfts = db.IntegerProperty()
    qfmj = db.IntegerProperty()
    xfts = db.IntegerProperty()
    xfmj = db.IntegerProperty()
    clfts = db.IntegerProperty()
    clfmj = db.IntegerProperty()
    disp_date = db.StringProperty()

if __name__=='__main__':
    update_database()
